﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public static class BoxCollider2DExtension
{
    public static Vector2 RandomBox(this BoxCollider2D boxCollider2D)
    {
        Vector2 center = (Vector2)boxCollider2D.transform.position + boxCollider2D.offset;

        // 获取BoxCollider2D的大小（世界坐标）
        Vector2 size = boxCollider2D.size;

        // 计算BoxCollider2D的左下角和右上角位置
        Vector2 bottomLeft = center - size / 2;
        Vector2 topRight = center + size / 2;

        // 在BoxCollider2D的范围内随机生成一个点
        float x = UnityEngine.Random.Range(bottomLeft.x, topRight.x);
        float y = UnityEngine.Random.Range(bottomLeft.y, topRight.y);

        return new Vector2(x, y);
    }

}

